package io.kerns.boot.web.config;

import io.kerns.boot.web.current.CurrentUserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * web 配置
 *
 * @author xiaohei
 * @create 2020-10-15 上午10:55
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 过滤掉swagger的请求访问
        List<String> urls = new ArrayList<>();
        urls.add("/doc.html");
        urls.add("/webjars/**");
        urls.add("/statics/**");
        urls.add("/swagger-resources");
        urls.add("/error");
        urls.add("/swagger-ui.html");
        //TODO 在这里注册自定义的拦截器
        registry.addInterceptor(new CurrentUserInterceptor()).addPathPatterns("/**").excludePathPatterns(urls);
    }

}
